package com.java.zhuiyun.api.pc_login.controller;

import cn.hutool.core.util.StrUtil;
import com.java.zhuiyun.api.front_desk_user.entity.FrontDeskUser;
import com.java.zhuiyun.api.pc_login.entity.Register;
import com.java.zhuiyun.api.pc_login.entity.SysUserDto;
import com.java.zhuiyun.api.pc_login.service.PcLoginService;
import com.java.zhuiyun.api.sys_user.entity.SysUser;
import com.java.zhuiyun.common.response.CommonConstants;
import com.java.zhuiyun.common.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PcLoginController
 * @Description TODO PC登录
 * @Author WX
 * @Date 2023/8/23 15:20
 **/
@RequestMapping("/pcLogin")
@RestController
@CrossOrigin
public class PcLoginController {
    @Autowired
    private PcLoginService pcLoginService;

    /*
    * @Author WX
    * @Description 登录查询
    * @Date 2023/8/23 15:28
    * @Return
    * @param null
    */
    @PostMapping("/login")
    public CommonResult login (@RequestBody FrontDeskUser frontDeskUser){
        String frontDeskPassword=frontDeskUser.getFrontDeskPassword();
        String frontDeskAccount = frontDeskUser.getFrontDeskAccount();
        if(StrUtil.isBlank(frontDeskPassword) || StrUtil.isBlank(frontDeskAccount)){
            return CommonResult.error(CommonConstants.ERROR);
        }
        SysUserDto sysUserDto = pcLoginService.login(frontDeskUser);
        return CommonResult.ok(sysUserDto);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 注册
    * @Date 2023/8/28 8:36
    * @Return
    * @param
    */
    @PostMapping("/register")
    public CommonResult register(@RequestBody Register register){

        return pcLoginService.register(register);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 手机号发送验证码
    * @Date 2023/8/28 8:36
    * @Return
    * @param
    */
    @PostMapping("/phoneSendCode")
    public CommonResult phoneSendCode(@RequestBody Register register) throws Exception {
        return pcLoginService.phoneSendCode(register);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 手机号验证码登录
    * @Date 2023/8/30 8:28
    * @Return
    * @param
    */
    @PostMapping("/phoneCodeLogin")
    public CommonResult phoneCodeLogin(@RequestBody Register register){
        return pcLoginService.phoneCodeLogin(register);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 手机号密码登录
    * @Date 2023/8/28 8:36
    * @Return
    * @param
    */
    @PostMapping("/phoneLogin")
    public CommonResult phoneLogin(@RequestBody Register register){
        return pcLoginService.phoneLogin(register);
    }

    /**
    * @Author 杨友朋
    * @Description TODO 邮箱发送验证码
    * @Date 2023/8/28 8:35
    * @Return
    * @param
    */
    @PostMapping("/emailSendCode")
    public CommonResult emailSendCode(@RequestBody Register register){
        return pcLoginService.emailSendCode(register);
    }

    @PostMapping("/emailCodeLogin")
    public CommonResult emailCodeLogin(@RequestBody Register register){
        return pcLoginService.emailCodeLogin(register);
    }

    @PostMapping("/emailLogin")
    public CommonResult emailLogin(@RequestBody Register register) {

        return pcLoginService.emailLogin(register);
    }
}
